import { Column, CreateDateColumn, Entity, JoinTable, ManyToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
import { Permission } from '../../permission/entities/permission.entity'
import { User } from '../../user/entities/user.entity'
import { Menu } from '../../menu/entities/menu.entity'

@Entity({
  name: 'roles',
})
export class Role {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ length: 20, comment: '角色名', unique: true })
  name: string

  @Column({ length: 100, comment: '角色描述' })
  description: string

  @CreateDateColumn()
  createTime: Date

  @UpdateDateColumn()
  updateTime: Date

  @ManyToMany(() => User)
  users: User[]

  @ManyToMany(() => Permission)
  @JoinTable({
    name: 'role_permissions',
  })
  permissions: Permission[]

  @ManyToMany(() => Menu)
  @JoinTable({
    name: 'role_menu',
  })
  menu: Menu[]
}
